package com.gsnd.gsnd22estore.web.controller;


import com.gsnd.gsnd22estore.domain.EsUser;
import com.gsnd.gsnd22estore.dto.*;
import com.gsnd.gsnd22estore.result.Result;
import com.gsnd.gsnd22estore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;


    @PostMapping("/login")
    public Result<LoginReturnDto> login(@RequestBody UserLoginDto userLogin)
    {
        return Result.success(userService.userLogin(userLogin));
    }
    @GetMapping("/getUserInfo")
    public Result<UserDto> getUserInfo(HttpServletRequest request){
        return Result.success(userService.getUserInfo(request));
    }
    @PostMapping("/register")
    public Result <String> register(@RequestBody UserRegisterDto userRegisterDto){
        userService.userRegister(userRegisterDto);
        return Result.success("恭喜注册成功");
    }
    @PutMapping("/updatePassword")
    public Result<String> updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto,HttpServletRequest request)
    {
        userService.updatePassword(updatePasswordDto,request);
        return Result.success("密码修改成功");
    }
    @PutMapping("/updateUser")
    public Result<String> updateUser(@RequestBody UpdateUserDto updateUserDto)
    {
        userService.updateUser(updateUserDto);
        return Result.success("成功");
    }
}
